﻿namespace Microsoft.SharePoint.Client
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;

    [ScriptType("SP.RoleDefinitionBindingCollection", ServerTypeId="{07bf1941-6953-4761-b114-58374b4aaf57}")]
    public class RoleDefinitionBindingCollection : ClientObjectCollection<RoleDefinition>
    {
        public RoleDefinitionBindingCollection(ClientRuntimeContext Context) : this(Context, new ObjectPathConstructor(Context, "{07bf1941-6953-4761-b114-58374b4aaf57}", null))
        {
        }

        [EditorBrowsable(EditorBrowsableState.Never)]
        public RoleDefinitionBindingCollection(ClientRuntimeContext Context, ObjectPath ObjectPath) : base(Context, ObjectPath)
        {
        }

        [Remote]
        public void Add(RoleDefinition roleDefinition)
        {
            if (base.Context.ValidateOnClient && (roleDefinition == null))
            {
                throw ClientUtility.CreateArgumentNullException("roleDefinition");
            }
            ClientAction query = new ClientActionInvokeMethod(this, "Add", new object[] { roleDefinition });
            base.Context.AddQuery(query);
            base.AddChild(roleDefinition);
        }

        protected override bool InitOnePropertyFromJson(string peekedName, JsonReader reader)
        {
            bool flag = base.InitOnePropertyFromJson(peekedName, reader);
            if (flag)
            {
                return flag;
            }
            return flag;
        }

        private void OnRemoveAll()
        {
            List<object> data = base.Data;
            while (data.Count > 0)
            {
                data.RemoveAt(data.Count - 1);
            }
        }

        [Remote]
        public void Remove(RoleDefinition roleDefinition)
        {
            if (base.Context.ValidateOnClient && (roleDefinition == null))
            {
                throw ClientUtility.CreateArgumentNullException("roleDefinition");
            }
            ClientAction query = new ClientActionInvokeMethod(this, "Remove", new object[] { roleDefinition });
            base.Context.AddQuery(query);
            base.RemoveChild(roleDefinition);
        }

        [Remote]
        public void RemoveAll()
        {
            ClientAction query = new ClientActionInvokeMethod(this, "RemoveAll", null);
            base.Context.AddQuery(query);
            this.OnRemoveAll();
        }
    }
}

